package Solutions

func maximumDetonation(bombs [][]int) int {
	l := len(bombs)
	matrix := make([][]int, l)
	for i := 0; i < l; i++ {
		matrix[i] = make([]int, l)
	}
	for i := 0; i < l; i++ {
		matrix[i][i] = 1
		for j := i + 1; j < l; j++ {
			distance2 := square(bombs[i][0]-bombs[j][0]) + square(bombs[i][1]-bombs[j][1])
			if square(bombs[i][2]) >= distance2 {
				matrix[i][j] = 1
			}
			if square(bombs[j][2]) >= distance2 {
				matrix[j][i] = 1
			}

		}
	}
	ans := 0
	var que []int
	var mp map[int]struct{}
	for i := 0; i < l; i++ {
		que = make([]int, 0, l)
		mp =map[int]struct{}{}
		que = append(que, i)
		mp[i] = struct{}{}
		for j := 0; j < len(que); j++ {
			for k := 0; k < len(matrix[que[j]]); k++ {
				if matrix[que[j]][k] == 1 {
					if _, ok := mp[k]; !ok {
						que = append(que, k)
						mp[k] = struct{}{}
					}
				}
			}
		}
		if ans < len(mp) {
			ans = len(mp)
		}
	}
	return ans
}

func square(a int) int {
	return a * a
}